package com.testerhome;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

/**
 * @author shichenhui
 * @description
 * @createDate 2025/1/22  14:19
 */
public class LoginDemo {
    public static void main(String[] args) {
        WebDriver webDriver = new ChromeDriver();
        //导航到登录页
        webDriver.get("https://testerhome.com/account/sign_in");
        //刷新页面，因为这个网站有问题，默认进入一直加载中
        // webDriver.navigate().refresh();

        //输入账号
        webDriver.findElement(By.id("user_login")).sendKeys("liancheng2");
        //输入密码
        webDriver.findElement(By.id("user_password")).sendKeys("liancheng2");
        //点击登录
        webDriver.findElement(By.name("commit")).click();
        //校验登录是否成功
        try {
            Thread.sleep(1000*3);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        String source = webDriver.getPageSource();//这个方法没见过
        if (source.contains("提高自己的知名度，请添加个有个性的头像吧")){
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败");
        }


    }
}
